package com.kyl.controller;


import com.alibaba.fastjson.JSON;
import com.aliyun.iot20180120.Client;
import com.aliyun.iot20180120.models.QueryDeviceRequest;
import com.aliyun.iot20180120.models.QueryProductListRequest;
import com.aliyun.iot20180120.models.QueryProductListResponse;
import com.kyl.base.PageResponse;
import com.kyl.base.ResponseResult;
import com.kyl.service.DeviceService;
import com.kyl.vo.DeviceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author WanJl
 * @version 1.0
 * @title DeviceController
 * @description 智能监控设备管理相关接口
 * @create 2025/1/17
 */
@RestController
@RequestMapping(value = "/iot")
@Api(tags = "智能监控设备管理相关接口")
public class DeviceController {

    //使用阿里云IOT提供的客户端对象
    @Autowired
    private Client client;

    //使用连接阿里云IOT所需要的各种参数
    @Value("${kyl.aliyun.iotInstanceId}")
    private String iotInstanceId;

    @Resource
    private DeviceService deviceService;

    /**
     *
     * @param request
     * @return
     */
    @PostMapping("/QueryProductList")
    @ApiOperation(value = "查询产品列表", notes = "查询产品列表")
    public ResponseResult queryProductList(@RequestBody QueryProductListRequest request) throws Exception{
        //把我们要查询的公共实例ID作为参数传入
        request.setIotInstanceId(iotInstanceId);

        //通过该实例ID查询该实例下的所有产品
        QueryProductListResponse queryProductListResponse =
                client.queryProductList(request);
        return ResponseResult.success(queryProductListResponse.getBody().getData());
    }


    @PostMapping("/QueryDevice")
    @ApiOperation(value = "查询设备列表", notes = "查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> queryDeviceList(@RequestBody QueryDeviceRequest request) throws Exception{
        PageResponse<DeviceVo> pageResponse = deviceService.queryDeviceList(request);
        return ResponseResult.success(pageResponse);
    }





















}
